package org.jeecg.modules.demo.zhengchai.compensationdisbursement.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.demo.zhengchai.compensationdisbursement.entity.CompensationDisbursement;
import org.jeecg.modules.demo.zhengchai.compensationdisbursement.service.CompensationDisbursementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/compensation-disbursement")
public class CompensationDisbursementController {

    @Autowired
    private CompensationDisbursementService compensationDisbursementService;

    /**
     * 获取赔偿发放列表
     * @param page 分页对象
     * @param compensationDisbursement 查询条件
     * @return 分页结果
     */
    @GetMapping("/list")
    public Page<CompensationDisbursement> list(Page<CompensationDisbursement> page, CompensationDisbursement compensationDisbursement) {
        QueryWrapper<CompensationDisbursement> queryWrapper = new QueryWrapper<>(compensationDisbursement);
        return compensationDisbursementService.page(page, queryWrapper);
    }

    /**
     * 添加赔偿发放
     * @param compensationDisbursement 赔偿发放对象
     * @return 是否添加成功
     */
    @PostMapping("/add")
    public boolean add(@RequestBody CompensationDisbursement compensationDisbursement) {
        return compensationDisbursementService.save(compensationDisbursement);
    }

    /**
     * 修改赔偿发放
     * @param compensationDisbursement 赔偿发放对象
     * @return 是否修改成功
     */
    @PutMapping("/edit")
    public boolean edit(@RequestBody CompensationDisbursement compensationDisbursement) {
        return compensationDisbursementService.updateById(compensationDisbursement);
    }

    /**
     * 删除赔偿发放
     * @param id 赔偿发放ID
     * @return 是否删除成功
     */
    @DeleteMapping("/delete")
    public boolean delete(@RequestParam("id") Long id) {
        return compensationDisbursementService.removeById(id);
    }

    /**
     * 根据ID查询赔偿发放
     * @param id 赔偿发放ID
     * @return 赔偿发放对象
     */
    @GetMapping("/queryById")
    public CompensationDisbursement queryById(@RequestParam("id") Long id) {
        return compensationDisbursementService.getById(id);
    }
}
